<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>文件转Base64</title>
	<style type="text/css">
		textarea{
			width: 100%;
			height: 500px;
			margin-top: 40px;
		}
	</style>
</head>
<body>
	<div>
		<input id="file-input" type="file" style="width: 300px; height: 100px; background-color: #ddd;"></input>
	</div>
	<div>
		<textarea id="file-base"></textarea>
	</div>
	<div><button onClick="copyUrl2()">点击复制</button></div>
</body>
<script type="text/javascript">
	var input = document.getElementById('file-input');
	var textarea = document.getElementById('file-base');

	input.onchange = function(event){
		console.log(event);
	    var file = this.files[0];

	    var reader = new FileReader();   
	    reader.readAsDataURL(file);   
	    reader.onload = function(e){   
	        textarea.value = this.result;

	    }
	}
	function copyUrl2(){
		textarea.select(); // 选择对象
		document.execCommand("Copy"); // 执行浏览器复制命令
		alert("已复制好，可贴粘。");
	}
</script>
</html>